package com.tiger.sso;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * 白名单
 * @author andy
 *
 */
public class Whitelist {

	private List<String> whitelist;
	private String whitelistStr;
	
	public boolean match(String value) {
		List<String> whitelist = getWhitelist();
		if(whitelist == null || whitelist.isEmpty()) {
			return false;
		}
		return whitelist.contains(value);
	}

	public List<String> getWhitelist() {
		if(whitelist != null) {
			return whitelist;
		}
		if(StringUtils.isEmpty(whitelistStr)) {
			return whitelist;
		}
		whitelist = Arrays.asList(whitelistStr.split(","));
		return whitelist;
	}

	public void setWhitelist(List<String> whitelist) {
		this.whitelist = whitelist;
	}
	
	public String getWhitelistStr() {
		return whitelistStr;
	}

	public void setWhitelistStr(String whitelistStr) {
		this.whitelistStr = whitelistStr;
	}

}
